#include"inputfilestream.h"
#include<errno.h>
#include<iostream>
#include<cstdio>
#include<cstring>

void inputfilestream::open_s(const char *fileName)
{
        this->fp = fopen(fileName, "r");
        if(this->fp == NULL)
                std::cout << "Error opening stream: " << strerror( errno ) << std::endl;
}

bool inputfilestream::end_of_stream()
{
        if(feof(this->fp))
                return true;
        return false;
}


int inputfilestream::read_next()
{
        int* num = new int;
        if(!end_of_stream())
        {
                if(fread((void*)num, 1, sizeof(int), this->fp) != sizeof(int))
                        std::cout << "Error reading from stream: " << strerror( errno ) << std::endl;
                int data = (*num);
                delete num;
                return data;
        }
	return EOF;
}

void inputfilestream::close_i()
{
        int ret = fclose(this->fp);
        if(ret < 0)
                std::cout << "Error closing stream: " << strerror( errno ) << std::endl;
}
